package com.hxd.otc.module.order.presenter;


import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.order.activity.SaleOrderDetailActivity;
import com.hxd.otc.module.order.bean.AdOrderDetailBean;
import com.hxd.otc.module.order.contract.AdSaleOrderDetailContract;
import com.hxd.otc.module.order.model.AllOrderModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

/**
 * 包  名 :  com.hxd.otc.module.order.presenter
 * 类  名 :  OrderFinishedPresenter
 * 作  者 :  zjl
 * 时  间 :  2018/6/9 12:02
 * 描  述 :  ${TODO}订单完成
 */
public class AdSaleOrderDetailPresenter extends BasePresenter<AdSaleOrderDetailContract.View> implements AdSaleOrderDetailContract.Presenter {

    AllOrderModel model;

    public AdSaleOrderDetailPresenter(AdSaleOrderDetailContract.View view) {
        super(view);
        model = AllOrderModel.getInstance();
    }

    @Override
    public void start() {

    }

    @Override
    public void doLoadData(String... category) {

        model.getAdOrderDetailData(new BaseObserver<AdOrderDetailBean>() {
            @Override
            public void onNext(String title, AdOrderDetailBean bean) {
                mView.onSetData(bean);
                doShowNoMore();
            }

            @Override
            public void onError(int errType, String errMessage) {
                doShowNoMore();
            }

        }, mView.<BaseBean<AdOrderDetailBean>>bindAutoDispose(), category[0]);
    }

    @Override
    public void doShowNoMore() {
        mView.onHideLoading();
    }

    @Override
    public void confirmPayment(String... category) {
        model.receiveAdOrder(new BaseObserver() {
            @Override
            public void onNext(String title, Object bean) {

                mView.refreshView(SaleOrderDetailActivity.CONFIRM_PAYMENT_SUCCESS);
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }

        }, mView.<BaseBean>bindAutoDispose(), category[0]);

    }

    @Override
    public void withdrawalRep(String... category) {
        model.recallAdOrder(new BaseObserver() {
            @Override
            public void onNext(String title, Object bean) {
                mView.refreshView(SaleOrderDetailActivity.WITHDRAW_SUCCESS);
                mView.showToast(title);
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }


        }, mView.<BaseBean>bindAutoDispose(), category[0]);

    }
}
